<template><div><p>本文档最新版为 <a href="https://learnku.com/docs/laravel/10.x" target="_blank" rel="noopener noreferrer">10.x</a>，旧版本可能放弃维护，推荐阅读最新版！</p>
<h2 id="laravel-valet" tabindex="-1"><a class="header-anchor" href="#laravel-valet"><span>Laravel Valet</span></a></h2>
<ul>
<li><a href="#introduction">介绍</a></li>
<li><a href="#installation">安装</a>
<ul>
<li><a href="#upgrading-valet">升级 Valet</a></li>
</ul>
</li>
<li><a href="#serving-sites">服务站点</a>
<ul>
<li><a href="#the-park-command">Park 命令</a></li>
<li><a href="#the-link-command">Link 命令</a></li>
<li><a href="#securing-sites">通过 TLS 保护站点</a></li>
<li><a href="#serving-a-default-site">服务默认站点</a></li>
<li><a href="#per-site-php-versions">站点特定 PHP 版本</a></li>
</ul>
</li>
<li><a href="#sharing-sites">共享站点</a>
<ul>
<li><a href="#sharing-sites-on-your-local-network">在本地网络上共享站点</a></li>
</ul>
</li>
<li><a href="#site-specific-environment-variables">站点特定环境变量</a></li>
<li><a href="#proxying-services">代理服务</a></li>
<li><a href="#custom-valet-drivers">自定义 Valet 驱动程序</a>
<ul>
<li><a href="#local-drivers">本地驱动程序</a></li>
</ul>
</li>
<li><a href="#other-valet-commands">其他 Valet 命令</a></li>
<li><a href="#valet-directories-and-files">Valet 目录和文件</a>
<ul>
<li><a href="#disk-access">磁盘访问</a></li>
</ul>
</li>
</ul>
<h2 id="介绍" tabindex="-1"><a class="header-anchor" href="#介绍"><span>介绍</span></a></h2>
<blockquote>
<p>[!NOTE]<br>
想要在 macOS 或 Windows 上更轻松地开发 Laravel 应用程序吗？请查看 <a href="https://herd.laravel.com/" target="_blank" rel="noopener noreferrer">Laravel Herd</a>。Herd 包括您开始使用 Laravel 开发所需的一切，包括 Valet、PHP 和 Composer。</p>
</blockquote>
<p><a href="https://github.com/laravel/valet" target="_blank" rel="noopener noreferrer">Laravel Valet</a> 是为 macOS 极简主义者设计的开发环境。Laravel Valet 配置您的 Mac，在您的机器启动时始终在后台运行 <a href="https://www.nginx.com/" target="_blank" rel="noopener noreferrer">Nginx</a>。然后，使用 <a href="https://en.wikipedia.org/wiki/Dnsmasq" target="_blank" rel="noopener noreferrer">DnsMasq</a>，Valet 会将 <code v-pre>*.test</code> 域上的所有请求代理到安装在本地机器上的站点。</p>
<p>换句话说，Valet 是一个极速的 Laravel 开发环境，大约使用 7 MB 的 RAM。Valet 不是 <a href="https://learnku.com/docs/laravel/11.x/sail" target="_blank" rel="noopener noreferrer">Sail</a> 或 <a href="https://learnku.com/docs/laravel/11.x/homestead" target="_blank" rel="noopener noreferrer">Homestead</a> 的完全替代品，但如果您想要灵活的基础设施、极速体验，或者在内存有限的机器上工作，Valet 提供了一个很好的选择。</p>
<p>Valet 默认支持，但不限于以下内容：</p>
<ul>
<li><a href="https://laravel.com/" target="_blank" rel="noopener noreferrer">Laravel</a></li>
<li><a href="https://roots.io/bedrock/" target="_blank" rel="noopener noreferrer">Bedrock</a></li>
<li><a href="https://cakephp.org/" target="_blank" rel="noopener noreferrer">CakePHP 3</a></li>
<li><a href="https://www.concretecms.com/" target="_blank" rel="noopener noreferrer">ConcreteCMS</a></li>
<li><a href="https://contao.org/en/" target="_blank" rel="noopener noreferrer">Contao</a></li>
<li><a href="https://craftcms.com/" target="_blank" rel="noopener noreferrer">Craft</a></li>
<li><a href="https://www.drupal.org/" target="_blank" rel="noopener noreferrer">Drupal</a></li>
<li><a href="https://www.expressionengine.com/" target="_blank" rel="noopener noreferrer">ExpressionEngine</a></li>
<li><a href="https://jigsaw.tighten.co/" target="_blank" rel="noopener noreferrer">Jigsaw</a></li>
<li><a href="https://www.joomla.org/" target="_blank" rel="noopener noreferrer">Joomla</a></li>
<li><a href="https://github.com/themsaid/katana" target="_blank" rel="noopener noreferrer">Katana</a></li>
<li><a href="https://getkirby.com/" target="_blank" rel="noopener noreferrer">Kirby</a></li>
<li><a href="https://magento.com/" target="_blank" rel="noopener noreferrer">Magento</a></li>
<li><a href="https://octobercms.com/" target="_blank" rel="noopener noreferrer">OctoberCMS</a></li>
<li><a href="https://sculpin.io/" target="_blank" rel="noopener noreferrer">Sculpin</a></li>
<li><a href="https://www.slimframework.com/" target="_blank" rel="noopener noreferrer">Slim</a></li>
<li><a href="https://statamic.com/" target="_blank" rel="noopener noreferrer">Statamic</a></li>
<li>静态 HTML</li>
<li><a href="https://symfony.com/" target="_blank" rel="noopener noreferrer">Symfony</a></li>
<li><a href="https://wordpress.org/" target="_blank" rel="noopener noreferrer">WordPress</a></li>
<li><a href="https://framework.zend.com/" target="_blank" rel="noopener noreferrer">Zend</a></li>
</ul>
<p>然而，你可以通过自己的<a href="#custom-valet-drivers">自定义驱动程序</a>来扩展 Valet。</p>
<h2 id="安装" tabindex="-1"><a class="header-anchor" href="#安装"><span>安装</span></a></h2>
<blockquote>
<p>[!WARNING]<br>
Valet 需要 macOS 和 <a href="https://brew.sh/" target="_blank" rel="noopener noreferrer">Homebrew</a>。在安装之前，你应确保没有其他程序（如 Apache 或 Nginx）绑定到您本地机器的端口 80。</p>
</blockquote>
<p>要开始之前，首先需要确保使用 <code v-pre>update</code> 命令使 Homebrew 处于最新状态：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">brew update</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>接下来，你应该使用 Homebrew 安装 PHP：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">brew <span class="token function">install</span> php</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>安装完 PHP 后，就可以安装 <a href="https://getcomposer.org/" target="_blank" rel="noopener noreferrer">Composer 包管理器</a>。此外，你应确保 <code v-pre>$HOME/.composer/vendor/bin</code> 目录在你系统的 「PATH」 中。安装完 Composer 后，你可以将 Laravel Valet 安装为全局 Composer 包：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token function">composer</span> global require laravel/valet</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>最后，你可以执行 Valet 的 <code v-pre>install</code> 命令。这将配置和安装 Valet 和 DnsMasq。此外，Valet 依赖的守护程序将被配置为在系统启动时启动：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet <span class="token function">install</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>安装完 Valet 后，你可以尝试在终端上使用类似 <code v-pre>ping foobar.test</code> 的命令来 ping 任何 <code v-pre>*.test</code> 域。如果 Valet 安装正确，应该看到该域正在 <code v-pre>127.0.0.1</code> 上响应。</p>
<p>Valet 将在每次启动您的机器时自动启动其所需的服务。</p>
<h4 id="php-版本" tabindex="-1"><a class="header-anchor" href="#php-版本"><span>PHP 版本</span></a></h4>
<blockquote>
<p>[!NOTE]<br>
您可以通过 <code v-pre>isolate</code> <a href="#per-site-php-versions">命令</a>指示 Valet 使用每个站点的 PHP 版本，而不是修改全局 PHP 版本。</p>
</blockquote>
<p>Valet 允许使用 <code v-pre>valet use php@version</code> 命令切换 PHP 版本。如果指定的 PHP 版本尚未安装，Valet 将通过 Homebrew 安装它：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet use php@8.2</span>
<span class="line"></span>
<span class="line">valet use php</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>你也可以在项目的根目录中创建一个 <code v-pre>.valetrc</code> 文件。<code v-pre>.valetrc</code> 文件应包含站点应该使用的PHP版本：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token assign-left variable">php</span><span class="token operator">=</span>php@8.2</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>创建完这个文件后，你可以简单地执行 <code v-pre>valet use</code> 命令，该命令将通过读取文件来确定站点的首选PHP版本。</p>
<blockquote>
<p>[!警告]<br>
Valet一次只能提供一个PHP版本，即使你安装了多个PHP版本。</p>
</blockquote>
<h4 id="数据库" tabindex="-1"><a class="header-anchor" href="#数据库"><span>数据库</span></a></h4>
<p>如果你的应用程序需要数据库，请查看 <a href="https://dbngin.com/" target="_blank" rel="noopener noreferrer">DBngin</a>，它提供了一个免费的一体化数据库管理工具，包括MySQL、PostgreSQL和Redis。安装完DBngin后，你可以使用 <code v-pre>root</code> 用户名和空字符串作为密码在 <code v-pre>127.0.0.1</code> 上连接到你的数据库。</p>
<h4 id="重置你的安装" tabindex="-1"><a class="header-anchor" href="#重置你的安装"><span>重置你的安装</span></a></h4>
<p>如果你在让Valet安装正常运行方面遇到问题，执行 <code v-pre>composer global require laravel/valet</code> 命令，然后执行 <code v-pre>valet install</code> 将重置你的安装并可以解决各种问题。在罕见情况下，可能需要通过执行 <code v-pre>valet uninstall --force</code>，然后执行<code v-pre>valet install</code> 来「硬重置」Valet。</p>
<h3 id="升级valet" tabindex="-1"><a class="header-anchor" href="#升级valet"><span>升级Valet</span></a></h3>
<p>你可以通过在终端中执行 <code v-pre>composer global require laravel/valet</code> 命令来更新你的Valet安装。升级后，最好运行 <code v-pre>valet install</code> 命令，这样Valet可以根据需要对你的配置文件进行额外的升级。</p>
<h4 id="升级到valet-4" tabindex="-1"><a class="header-anchor" href="#升级到valet-4"><span>升级到Valet 4</span></a></h4>
<p>如果你从 Valet 3 升级到 Valet 4，请按照以下步骤正确升级你的Valet安装：</p>
<ul>
<li>如果你添加了 <code v-pre>.valetphprc</code> 文件来自定义站点的PHP版本，请将每个<code v-pre>.valetphprc</code> 文件重命名为 <code v-pre>.valetrc</code>。然后，在 <code v-pre>.valetrc</code> 文件的现有内容前加上 <code v-pre>php=</code>。</li>
<li>更新任何自定义驱动程序以匹配新驱动程序系统的命名空间、扩展、类型提示和返回类型提示。你可以参考Valet的<a href="https://github.com/laravel/valet/blob/d7787c025e60abc24a5195dc7d4c5c6f2d984339/cli/stubs/SampleValetDriver.php" target="_blank" rel="noopener noreferrer">SampleValetDriver</a>作为示例。</li>
<li>如果你使用PHP 7.1 - 7.4 来提供你的站点，请确保你仍然使用Homebrew安装一个PHP版本为8.0或更高版本，因为Valet将使用这个版本，即使它不是你的主要链接版本，来运行一些脚本。</li>
</ul>
<h3 id="提供站点" tabindex="-1"><a class="header-anchor" href="#提供站点"><span>提供站点</span></a></h3>
<p>安装好 Valet 后，你就可以开始提供你的 Laravel 应用程序了。Valet提供了两个命令来帮助你提供应用程序：<code v-pre>park</code> 和 <code v-pre>link</code>。</p>
<h3 id="park-命令" tabindex="-1"><a class="header-anchor" href="#park-命令"><span><code v-pre>park</code> 命令</span></a></h3>
<p><code v-pre>park</code> 命令会在你的机器上注册一个包含应用程序的目录。一旦目录被 Valet “停放”，该目录中的所有目录将可以在你的Web浏览器中访问，地址为 <code v-pre>http://&lt;目录名称&gt;.test</code>：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token builtin class-name">cd</span> ~/Sites</span>
<span class="line"></span>
<span class="line">valet park</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>就是这样。现在，你在“停放”目录中创建的任何应用程序都将自动使用 <code v-pre>http://&lt;目录名称&gt;.test</code> 约定进行提供。因此，如果你的停放目录包含一个名为 &quot;laravel&quot; 的目录，该目录中的应用程序将可以在 <code v-pre>http://laravel.test</code> 上访问。此外，Valet还允许你使用通配符子域名访问该站点（<code v-pre>http://foo.laravel.test</code>）。</p>
<h3 id="link-命令" tabindex="-1"><a class="header-anchor" href="#link-命令"><span><code v-pre>link</code> 命令</span></a></h3>
<p><code v-pre>link</code> 命令也可以用来提供你的 Laravel 应用程序。如果你只想在一个目录中提供单个站点而不是整个目录，这个命令就很有用：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token builtin class-name">cd</span> ~/Sites/laravel</span>
<span class="line"></span>
<span class="line">valet <span class="token function">link</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>一旦使用 <code v-pre>link</code> 命令将应用程序链接到 Valet，你可以使用其目录名称访问该应用程序。因此，在上面的示例中链接的站点可以在 <code v-pre>http://laravel.test</code> 上访问。此外，Valet还允许你使用通配符子域名访问该站点（<code v-pre>http://foo.laravel.test</code>）。</p>
<p>如果你想要在不同的主机名下提供应用程序，你可以将主机名传递给 <code v-pre>link</code> 命令。例如，你可以运行以下命令使一个应用程序在 <code v-pre>http://application.test</code> 上可用：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token builtin class-name">cd</span> ~/Sites/laravel</span>
<span class="line"></span>
<span class="line">valet <span class="token function">link</span> application</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>当然，你也可以使用<code v-pre>link</code>命令在子域上提供应用程序：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet <span class="token function">link</span> api.application</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>你可以执行<code v-pre>links</code>命令来显示所有已链接目录的列表：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet links</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p><code v-pre>unlink</code>命令可用于销毁站点的符号链接：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token builtin class-name">cd</span> ~/Sites/laravel</span>
<span class="line"></span>
<span class="line">valet unlink</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="使用tls保护站点" tabindex="-1"><a class="header-anchor" href="#使用tls保护站点"><span>使用TLS保护站点</span></a></h3>
<p>默认情况下，Valet通过HTTP提供站点服务。但是，如果你想要通过加密的TLS使用HTTP/2提供站点服务，你可以使用<code v-pre>secure</code>命令。例如，如果你的站点由Valet在<code v-pre>laravel.test</code>域上提供服务，你应该运行以下命令来保护它：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet secure laravel</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>要“取消安全”一个站点，并恢复将其流量通过普通HTTP提供服务，使用<code v-pre>unsecure</code>命令。与<code v-pre>secure</code>命令类似，这个命令接受你希望取消安全的主机名：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet unsecure laravel</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="提供默认站点" tabindex="-1"><a class="header-anchor" href="#提供默认站点"><span>提供默认站点</span></a></h3>
<p>有时，你可能希望配置Valet在访问未知的<code v-pre>test</code>域时提供一个“默认”站点，而不是<code v-pre>404</code>页面。为了实现这一点，你可以在你的<code v-pre>~/.config/valet/config.json</code>配置文件中添加一个<code v-pre>default</code>选项，其中包含应该作为默认站点的站点路径：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string double-quoted-string">"default"</span><span class="token punctuation">:</span> <span class="token string double-quoted-string">"/Users/Sally/Sites/example-site"</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="每个站点的php版本" tabindex="-1"><a class="header-anchor" href="#每个站点的php版本"><span>每个站点的PHP版本</span></a></h3>
<p>默认情况下，Valet使用全局PHP安装来提供站点服务。然而，如果你需要在各个站点上支持多个PHP版本，你可以使用<code v-pre>isolate</code>命令来指定特定站点应该使用哪个PHP版本。<code v-pre>isolate</code>命令配置Valet在你当前工作目录中的站点使用指定的PHP版本：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token builtin class-name">cd</span> ~/Sites/example-site</span>
<span class="line"></span>
<span class="line">valet isolate php@8.0</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>如果你的站点名称与包含它的目录名称不匹配，你可以使用<code v-pre>--site</code>选项指定站点名称：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet isolate php@8.0 <span class="token parameter variable">--site</span><span class="token operator">=</span><span class="token string">"site-name"</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>为了方便起见，你可以使用<code v-pre>valet php</code>、<code v-pre>composer</code>和<code v-pre>which-php</code>命令来代理调用适当的PHP CLI或工具，根据站点配置的PHP版本：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet php</span>
<span class="line">valet <span class="token function">composer</span></span>
<span class="line">valet which-php</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>你可以执行<code v-pre>isolated</code>命令来显示所有被隔离的站点及其PHP版本的列表：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet isolated</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>要将一个站点恢复到Valet全局安装的PHP版本，你可以从站点的根目录调用<code v-pre>unisolate</code>命令：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet unisolate</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h2 id="分享站点" tabindex="-1"><a class="header-anchor" href="#分享站点"><span>分享站点</span></a></h2>
<p>Valet包含一个命令，可以让你将本地站点与世界分享，为你在移动设备上测试站点或与团队成员和客户分享提供了一种简单的方式。</p>
<p>Valet默认支持通过ngrok或Expose分享你的站点。在分享站点之前，你应该使用<code v-pre>share-tool</code>命令更新你的Valet配置，指定<code v-pre>ngrok</code>或<code v-pre>expose</code>：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet share-tool ngrok</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>如果你选择了一个工具，但没有通过Homebrew（对于ngrok）或Composer（对于Expose）安装它，Valet会自动提示你安装它。当然，你需要在开始分享站点之前先认证你的ngrok或Expose账户。</p>
<p>要分享一个站点，进入终端中站点的目录并运行Valet的<code v-pre>share</code>命令。一个可公开访问的URL将被放入你的剪贴板，准备直接粘贴到你的浏览器中或与你的团队分享：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token builtin class-name">cd</span> ~/Sites/laravel</span>
<span class="line"></span>
<span class="line">valet share</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>停止分享你的站点，你可以按下<code v-pre>Control + C</code>。</p>
<blockquote>
<p>[!警告]<br>
如果你正在使用自定义DNS服务器（如<code v-pre>1.1.1.1</code>），ngrok分享可能无法正常工作。如果在你的设备上是这种情况，请打开你的Mac系统设置，进入网络设置，打开高级设置，然后转到DNS选项卡，并将<code v-pre>127.0.0.1</code>添加为你的第一个DNS服务器。</p>
</blockquote>
<h4 id="通过ngrok分享站点" tabindex="-1"><a class="header-anchor" href="#通过ngrok分享站点"><span>通过Ngrok分享站点</span></a></h4>
<p>使用ngrok分享你的站点需要你<a href="https://dashboard.ngrok.com/signup" target="_blank" rel="noopener noreferrer">创建一个ngrok账户</a>并<a href="https://dashboard.ngrok.com/get-started/your-authtoken" target="_blank" rel="noopener noreferrer">设置一个认证令牌</a>。一旦你有了认证令牌，你可以使用该令牌更新你的Valet配置：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet set-ngrok-token YOUR_TOKEN_HERE</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><blockquote>
<p>[!注意]<br>
你可以向分享命令传递额外的ngrok参数，比如<code v-pre>valet share --region=eu</code>。欲了解更多信息，请参阅<a href="https://ngrok.com/docs" target="_blank" rel="noopener noreferrer">ngrok文档</a>。</p>
</blockquote>
<h4 id="通过expose分享站点" tabindex="-1"><a class="header-anchor" href="#通过expose分享站点"><span>通过Expose分享站点</span></a></h4>
<p>使用Expose分享你的站点需要你<a href="https://expose.dev/register" target="_blank" rel="noopener noreferrer">创建一个Expose账户</a>并<a href="https://expose.dev/docs/getting-started/getting-your-token" target="_blank" rel="noopener noreferrer">通过你的认证令牌与Expose进行认证</a>。</p>
<p>你可以查阅<a href="https://expose.dev/docs" target="_blank" rel="noopener noreferrer">Expose文档</a>以获取关于它支持的额外命令行参数的信息。</p>
<h3 id="在本地网络上分享站点" tabindex="-1"><a class="header-anchor" href="#在本地网络上分享站点"><span>在本地网络上分享站点</span></a></h3>
<p>Valet默认将传入流量限制在内部的<code v-pre>127.0.0.1</code>接口，以防止你的开发机器受到来自互联网的安全风险。</p>
<p>如果你希望允许本地网络上的其他设备通过你的机器的IP地址（例如：<code v-pre>192.168.1.10/application.test</code>）访问你机器上的 Valet 站点，你需要手动编辑相应站点的Nginx配置文件，以移除 <code v-pre>listen</code> 指令上的限制。你应该移除端口80和443上 <code v-pre>listen</code> 指令的 <code v-pre>127.0.0.1:</code> 前缀。</p>
<h3 id="如果未在项目上运行-valet-secure" tabindex="-1"><a class="header-anchor" href="#如果未在项目上运行-valet-secure"><span>如果未在项目上运行 <code v-pre>valet secure</code></span></a></h3>
<p>如果你尚未在项目上运行 <code v-pre>valet secure</code>，可以通过编辑 <code v-pre>/usr/local/etc/nginx/valet/valet.conf</code> 文件为所有非 HTTPS 站点打开网络访问。但是，如果你正在通过 HTTPS 提供项目站点（已为站点运行 <code v-pre>valet secure</code>），那么应该编辑 <code v-pre>~/.config/valet/Nginx/app-name.test</code> 文件。</p>
<p>更新 Nginx 配置后，运行 <code v-pre>valet restart</code> 命令以应用配置更改。</p>
<h2 id="站点特定环境变量" tabindex="-1"><a class="header-anchor" href="#站点特定环境变量"><span>站点特定环境变量</span></a></h2>
<p>一些使用其他框架的应用程序可能依赖于服务器环境变量，但没有提供在项目内配置这些变量的方式。Valet 允许在项目根目录中添加一个 <code v-pre>.valet-env.php</code> 文件来配置站点特定的环境变量。该文件应返回一个「站点/环境变量」对的数组，这些对将被添加到全局 <code v-pre>$_SERVER</code> 数组中，用于数组中指定的每个站点：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">return</span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token comment">// 为 laravel.test 站点设置 $_SERVER['key'] 为 "value"...</span></span>
<span class="line">    <span class="token string single-quoted-string">'laravel'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'key'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'value'</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span>
<span class="line">    <span class="token comment">// 为所有站点设置 $_SERVER['key'] 为 "value"...</span></span>
<span class="line">    <span class="token string single-quoted-string">'*'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'key'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'value'</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">;</span></span>
<span class="line"></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="代理服务" tabindex="-1"><a class="header-anchor" href="#代理服务"><span>代理服务</span></a></h2>
<p>有时你可能希望将 Valet 域代理到本地计算机上的另一个服务。例如可能偶尔需要在运行 Docker 的同时运行 Valet 的独立站点；但是，Valet 和 Docker 不能同时绑定到端口 80。</p>
<p>为解决这个问题，可以使用 <code v-pre>proxy</code> 命令生成代理。例如，可以将来自 <code v-pre>http://elasticsearch.test</code> 的所有流量代理到 <code v-pre>http://127.0.0.1:9200</code>：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token comment"># 通过 HTTP 进行代理...</span></span>
<span class="line">valet proxy elasticsearch http://127.0.0.1:9200</span>
<span class="line"></span>
<span class="line"><span class="token comment"># 通过 TLS + HTTP/2 进行代理...</span></span>
<span class="line">valet proxy elasticsearch http://127.0.0.1:9200 <span class="token parameter variable">--secure</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="移除代理和列出代理配置" tabindex="-1"><a class="header-anchor" href="#移除代理和列出代理配置"><span>移除代理和列出代理配置</span></a></h3>
<p>可以使用 <code v-pre>unproxy</code> 命令来移除代理：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet unproxy elasticsearch</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>可以使用 <code v-pre>proxies</code> 命令列出所有被代理的站点配置：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">valet proxies</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h2 id="自定义-valet-驱动程序" tabindex="-1"><a class="header-anchor" href="#自定义-valet-驱动程序"><span>自定义 Valet 驱动程序</span></a></h2>
<p>你可以编写自己的 Valet 「驱动程序」，用于为 Valet 原生不支持的框架或 CMS 上运行的 PHP 应用程序提供服务。安装 Valet 时，会创建一个 <code v-pre>~/.config/valet/Drivers</code> 目录，其中包含一个 <code v-pre>SampleValetDriver.php</code> 文件。该文件包含一个演示如何编写自定义驱动程序的示例实现。编写驱动程序只需要实现三个方法：<code v-pre>serves</code>、<code v-pre>isStaticFile</code> 和 <code v-pre>frontControllerPath</code>。</p>
<p>这三个方法都以 <code v-pre>$sitePath</code>、<code v-pre>$siteName</code> 和 <code v-pre>$uri</code> 作为参数。<code v-pre>$sitePath</code> 是您机器上提供服务的站点的完全限定路径，例如 <code v-pre>/Users/Lisa/Sites/my-project</code>。<code v-pre>$siteName</code> 是域名的 「host」 / 「site name」 部分（<code v-pre>my-project</code>）。<code v-pre>$uri</code> 是传入的请求 URI（<code v-pre>/foo/bar</code>）。</p>
<p>完成你自定义的 Valet 驱动程序后，请将其放置在 <code v-pre>~/.config/valet/Drivers</code> 目录中，并使用 <code v-pre>FrameworkValetDriver.php</code> 命名约定。例如，如果你正在为 WordPress 编写自定义 Valet 驱动程序，则文件名应为 <code v-pre>WordPressValetDriver.php</code>。</p>
<p>让我们看一下自定义的 Valet 驱动程序应实现的每个方法的示例实现。</p>
<h4 id="serves-方法" tabindex="-1"><a class="header-anchor" href="#serves-方法"><span><code v-pre>serves</code> 方法</span></a></h4>
<p>如果驱动程序应处理传入请求，则 <code v-pre>serves</code> 方法应返回 <code v-pre>true</code>。否则，该方法应返回 <code v-pre>false</code>。因此，在此方法中，你应尝试确定给定的 <code v-pre>$sitePath</code> 是否包含要提供服务的类型的项目。</p>
<p>例如，让我们想象我们正在编写一个 <code v-pre>WordPressValetDriver</code>。我们的 <code v-pre>serves</code> 方法可能如下所示：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * Determine if the driver serves the request.</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">serves</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$sitePath</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$siteName</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$uri</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">bool</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">return</span> <span class="token function">is_dir</span><span class="token punctuation">(</span><span class="token variable">$sitePath</span><span class="token operator">.</span><span class="token string single-quoted-string">'/wp-admin'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="isstaticfile-方法" tabindex="-1"><a class="header-anchor" href="#isstaticfile-方法"><span><code v-pre>isStaticFile</code> 方法</span></a></h4>
<p><code v-pre>isStaticFile</code> 方法应确定传入请求是否是针对「静态」文件，例如图像或样式表。如果文件是静态的，该方法应返回磁盘上静态文件的完全限定路径。如果传入请求不是针对静态文件，则该方法应返回 <code v-pre>false</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * Determine if the incoming request is for a static file.</span>
<span class="line"> *</span>
<span class="line"> * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">string</span><span class="token punctuation">|</span><span class="token keyword">false</span></span></span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">isStaticFile</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$sitePath</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$siteName</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$uri</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token function">file_exists</span><span class="token punctuation">(</span><span class="token variable">$staticFilePath</span> <span class="token operator">=</span> <span class="token variable">$sitePath</span><span class="token operator">.</span><span class="token string single-quoted-string">'/public/'</span><span class="token operator">.</span><span class="token variable">$uri</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">return</span> <span class="token variable">$staticFilePath</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token keyword">return</span> <span class="token constant boolean">false</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><blockquote>
<p>[!WARNING]<br>
<code v-pre>isStaticFile</code> 方法仅在 <code v-pre>serves</code> 方法对传入请求返回 <code v-pre>true</code> 且请求 URI 不是 <code v-pre>/</code> 时才会被调用。</p>
</blockquote>
<h4 id="frontcontrollerpath-方法" tabindex="-1"><a class="header-anchor" href="#frontcontrollerpath-方法"><span><code v-pre>frontControllerPath</code> 方法</span></a></h4>
<p><code v-pre>frontControllerPath</code> 方法应返回应用程序的“前端控制器”的完全限定路径，通常是一个 &quot;index.php&quot; 文件或等效文件：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * Get the fully resolved path to the application's front controller.</span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">frontControllerPath</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$sitePath</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$siteName</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$uri</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">string</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">return</span> <span class="token variable">$sitePath</span><span class="token operator">.</span><span class="token string single-quoted-string">'/public/index.php'</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="本地驱动程序" tabindex="-1"><a class="header-anchor" href="#本地驱动程序"><span>本地驱动程序</span></a></h3>
<p>如果你想为单个应用程序定义自定义 Valet 驱动程序，请在应用程序的根目录中创建一个 <code v-pre>LocalValetDriver.php</code> 文件。您的自定义驱动程序可以扩展基本的 <code v-pre>ValetDriver</code> 类或扩展现有的特定应用程序驱动程序，如 <code v-pre>LaravelValetDriver</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Valet<span class="token punctuation">\</span>Drivers<span class="token punctuation">\</span>LaravelValetDriver</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">LocalValetDriver</span> <span class="token keyword">extends</span> <span class="token class-name">LaravelValetDriver</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * Determine if the driver serves the request.</span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">serves</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$sitePath</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$siteName</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$uri</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">bool</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">return</span> <span class="token constant boolean">true</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * Get the fully resolved path to the application's front controller.</span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">frontControllerPath</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$sitePath</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$siteName</span><span class="token punctuation">,</span> <span class="token keyword type-hint">string</span> <span class="token variable">$uri</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">string</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">return</span> <span class="token variable">$sitePath</span><span class="token operator">.</span><span class="token string single-quoted-string">'/public_html/index.php'</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="其他-valet-命令" tabindex="-1"><a class="header-anchor" href="#其他-valet-命令"><span>其他 Valet 命令</span></a></h3>
<p>命令 | 描述 ------------- | ------------- `valet list` | 显示所有 Valet 命令的列表。 `valet diagnose` | 输出诊断信息以帮助调试 Valet。 `valet directory-listing` | 确定目录列表行为。默认为 「off」，对目录呈现 404 页面。 `valet forget` | 从 「parked」 目录中运行此命令以将其从停放目录列表中移除。 `valet log` | 查看由 Valet 服务编写的日志列表。 `valet paths` | 查看所有您的 「parked」 路径。 `valet restart` | 重新启动 Valet 守护进程。 `valet start` | 启动 Valet 守护进程。 `valet stop` | 停止 Valet 守护进程。 `valet trust` | 为 Brew 和 Valet 添加 sudoers 文件，以允许无需提示输入密码运行 Valet 命令。 `valet uninstall` | 卸载 Valet：显示手动卸载的说明。使用 `--force` 选项来强制删除所有 Valet 资源。</p>
<h3 id="valet-目录和文件" tabindex="-1"><a class="header-anchor" href="#valet-目录和文件"><span>Valet 目录和文件</span></a></h3>
<p>在排除 Valet 环境问题时，以下目录和文件信息有所帮助：</p>
<h4 id="config-valet" tabindex="-1"><a class="header-anchor" href="#config-valet"><span><code v-pre>~/.config/valet</code></span></a></h4>
<p>包含所有 Valet 的配置。你可能希望保留此目录的备份。</p>
<h4 id="config-valet-dnsmasq-d" tabindex="-1"><a class="header-anchor" href="#config-valet-dnsmasq-d"><span><code v-pre>~/.config/valet/dnsmasq.d/</code></span></a></h4>
<p>目录包含 DNSMasq 的配置。</p>
<h4 id="config-valet-drivers" tabindex="-1"><a class="header-anchor" href="#config-valet-drivers"><span><code v-pre>~/.config/valet/Drivers/</code></span></a></h4>
<p>目录包含 Valet 的驱动程序。驱动程序确定特定框架/CMS 的提供方式。</p>
<h4 id="config-valet-nginx" tabindex="-1"><a class="header-anchor" href="#config-valet-nginx"><span><code v-pre>~/.config/valet/Nginx/</code></span></a></h4>
<p>目录包含所有 Valet 的 Nginx 站点配置。运行 <code v-pre>install</code> 和 <code v-pre>secure</code> 命令时，这些文件会重新构建。</p>
<h4 id="config-valet-sites" tabindex="-1"><a class="header-anchor" href="#config-valet-sites"><span><code v-pre>~/.config/valet/Sites/</code></span></a></h4>
<p>这个目录包含所有你的<a href="#the-link-command">已链接项目</a>的符号链接。</p>
<h3 id="config-valet-config-json" tabindex="-1"><a class="header-anchor" href="#config-valet-config-json"><span><code v-pre>~/.config/valet/config.json</code></span></a></h3>
<p>Valet 的主配置文件。</p>
<h3 id="config-valet-valet-sock" tabindex="-1"><a class="header-anchor" href="#config-valet-valet-sock"><span><code v-pre>~/.config/valet/valet.sock</code></span></a></h3>
<p>Valet 的 Nginx 安装所使用的 PHP-FPM 套接字。只有在 PHP 正常运行时才会存在。</p>
<h3 id="config-valet-log-fpm-php-www-log" tabindex="-1"><a class="header-anchor" href="#config-valet-log-fpm-php-www-log"><span><code v-pre>~/.config/valet/Log/fpm-php.www.log</code></span></a></h3>
<p>PHP 错误的用户日志。</p>
<h3 id="config-valet-log-nginx-error-log" tabindex="-1"><a class="header-anchor" href="#config-valet-log-nginx-error-log"><span><code v-pre>~/.config/valet/Log/nginx-error.log</code></span></a></h3>
<p>Nginx 错误的用户日志。</p>
<h3 id="usr-local-var-log-php-fpm-log" tabindex="-1"><a class="header-anchor" href="#usr-local-var-log-php-fpm-log"><span><code v-pre>/usr/local/var/log/php-fpm.log</code></span></a></h3>
<p>PHP-FPM 错误的系统日志。</p>
<h3 id="usr-local-var-log-nginx" tabindex="-1"><a class="header-anchor" href="#usr-local-var-log-nginx"><span><code v-pre>/usr/local/var/log/nginx</code></span></a></h3>
<p>目录包含 Nginx 访问和错误日志。</p>
<h3 id="usr-local-etc-php-x-x-conf-d" tabindex="-1"><a class="header-anchor" href="#usr-local-etc-php-x-x-conf-d"><span><code v-pre>/usr/local/etc/php/X.X/conf.d</code></span></a></h3>
<p>目录包含各种 PHP 配置设置的 <code v-pre>*.ini</code> 文件。</p>
<h3 id="usr-local-etc-php-x-x-php-fpm-d-valet-fpm-conf" tabindex="-1"><a class="header-anchor" href="#usr-local-etc-php-x-x-php-fpm-d-valet-fpm-conf"><span><code v-pre>/usr/local/etc/php/X.X/php-fpm.d/valet-fpm.conf</code></span></a></h3>
<p>PHP-FPM 池配置文件。</p>
<h3 id="composer-vendor-laravel-valet-cli-stubs-secure-valet-conf" tabindex="-1"><a class="header-anchor" href="#composer-vendor-laravel-valet-cli-stubs-secure-valet-conf"><span><code v-pre>~/.composer/vendor/laravel/valet/cli/stubs/secure.valet.conf</code></span></a></h3>
<p>用于站点构建的 SSL 证书默认 Nginx 配置文件。</p>
<h3 id="磁盘访问" tabindex="-1"><a class="header-anchor" href="#磁盘访问"><span>磁盘访问</span></a></h3>
<p>从 macOS 10.14 开始，默认情况下<a href="https://manuals.info.apple.com/MANUALS/1000/MA1902/en_US/apple-platform-security-guide.pdf" target="_blank" rel="noopener noreferrer">限制了对某些文件和目录的访问</a>。这些限制包括桌面、文稿和下载目录。此外，网络卷和可移动卷的访问也受限。因此，Valet 建议您的站点文件夹位于这些受保护位置之外。</p>
<p>然而，如果你希望从其中一个位置提供站点服务，你需要授予 Nginx 「完全磁盘访问权限」。否则，你可能会遇到来自 Nginx 的服务器错误或其他不可预测的行为，特别是在提供静态资源时。通常情况下，macOS 将自动提示你授予 Nginx 对这些位置的完全访问权限。或者，也可以通过 <code v-pre>系统偏好设置</code> &gt; <code v-pre>安全性与隐私</code> &gt; <code v-pre>隐私</code> 并选择 <code v-pre>完全磁盘访问</code> 来手动执行此操作。接下来，在主窗格中启用任何 <code v-pre>nginx</code> 条目。</p>
<blockquote>
<p>本译文仅用于学习和交流目的，转载请务必注明文章译者、出处、和本文链接<br>
我们的翻译工作遵照 <a href="https://learnku.com/docs/guide/cc4.0/6589" target="_blank" rel="noopener noreferrer">CC 协议</a>，如果我们的工作有侵犯到您的权益，请及时联系我们。</p>
</blockquote>
<hr>
<blockquote>
<p>原文地址：<a href="https://learnku.com/docs/laravel/11.x/valetmd/16736" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/11.x/va...</a></p>
<p>译文地址：<a href="https://learnku.com/docs/laravel/11.x/valetmd/16736" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/11.x/va...</a></p>
</blockquote>
</div></template>


